<?php
/**
 * Default 2 player battle setup
 *
 */
class Default_Battle{
	/**
	 * Start a default battle withthe specified playerIds
	 *
	 * @param int $playerId_1
	 * @param int $playerId_2
	 * @return int $newBattleId
	 */
	public function CreateDefault2PlayerBattle($playerId_1, $playerId_2){
		//Create a new battle instance(and retrieve battleId)
		$newBattleId = BattleCommand::CreateBattle($playerId_1, $playerId_2);
		//Populate new battle instance with both players Units
		DeployDefaultStartingUnits($newBattleId, $playerId_1, $playerId_2);
		
		//Now the battle is populated, return the id
		return $newBattleId;
	}
	
	/**
	 * Deploy the units of a default 2 player battle (Player1 always has active turn and starts on East of map!)
	 *
	 * @return Array of units in this battle
	 */
	private function DeployDefaultStartingUnits($battleId, $player1_Id, $player2_Id){
		//Create starting Units for both players
		$db = Database::getInstance();
		
		//	PLAYER 1 - EAST TEAM
		$activeTurnString = "Y"; //Active Player turn
		$params = array($battleId, $playerId, 0, $activeTurnString, 1, 3, 90);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		$params = array($battleId, $playerId, 0, $activeTurnString, 2, 4, 90);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		$params = array($battleId, $playerId, 0, $activeTurnString, 3, 5, 90);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		$params = array($battleId, $playerId, 0, $activeTurnString, 2, 6, 90);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		$params = array($battleId, $playerId, 0, $activeTurnString, 1, 7, 90);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		 
		//	PLAYER 2 - WEST TEAM
		$activeTurnString = "N"; //Inactive Player
		$params = array($battleId, $playerId, 0, $activeTurnString, 10, 3, 270);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		$params = array($battleId, $playerId, 0, $activeTurnString, 9, 4, 270);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		$params = array($battleId, $playerId, 0, $activeTurnString, 8, 5, 270);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		$params = array($battleId, $playerId, 0, $activeTurnString, 9, 6, 270);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		$params = array($battleId, $playerId, 0, $activeTurnString, 10, 7, 270);
		$db->callSP(Config::sP_Unit1T_Create, $params);
		
		//DONE - We now have a populated battle in the DB
	}
}

?>